package main

import (
	"bufio"
	"fmt"
	"log"
	"net"
	"test_chat/client"
	"test_chat/server"
	"test_chat/server_udp"
	"time"
)

func main() {
	//test_udp()

	// rpc
	//go server.TestRpcSerer()
	//time.Sleep(3 * time.Second)
	//log.Println("Sleep end")
	//client.TestClient()

	// grpc
	go server.TestServer()
	time.Sleep(3 * time.Second)
	fmt.Println("Sleep 3 second end")
	client.TestGrpcClient()

}

func test_udp() {
	go server_udp.Receive()
	time.Sleep(3 * time.Second)
	log.Println("Sleep ending")
	p := make([]byte, 1024)
	conn, err := net.Dial("udp", "127.0.0.1:7778")
	if err != nil {
		fmt.Println(err)
	}
	log.Println("Client lian jie")
	defer conn.Close()
	fmt.Fprintf(conn, "HI sercver udp")
	n, err := bufio.NewReader(conn).Read(p)
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(string(p[:n]))
	}

}
